
var appConfing = require("../../app_modules/dbAccess/appConfig.js");
var multiparty = require('multiparty');
var fs = require('fs');

exports.saveFile=function(inputFile,newFileName,fileType){  
  try{
        fileType=fileType.toLowerCase();
        var dirpath="./public/files/upload/";       
        if(fileType=="jpg"||fileType=="jpeg"||fileType=="bpm"||fileType=="png"||fileType=="gif"||fileType=="ico"){
                var images = require("images");
                var sourceImg = inputFile.path; 
                var imgSize=appConfing.getImsSize();
                for(g=0;g<imgSize.length;g++){
                     images(sourceImg).resize(imgSize[g])
                     .save(dirpath +imgSize[g].toString()+ newFileName, {});
                }          
                fs.rename(inputFile.path,dirpath + newFileName);
        }
        else{
          fs.rename(inputFile.path,dirpath + newFileName);
        }
  }
   catch(ex){
    console.log("catch:saveFile,"+ex.message);
   }
}

